//
//  AppDelegate.m
//  JZRJAPPT
//
//  Created by mac on 16/5/8.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "AppDelegate.h"
#import "HomeController.h"
#import "AutoChangerController.h"
#import "MessageController.h"
#import "ViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor whiteColor];
    
    // 首页
    UINavigationController *NVCHome = [[UINavigationController alloc] initWithRootViewController:[[HomeController alloc] init]];
    NVCHome.navigationBar.translucent = NO;
    
    NVCHome.tabBarItem.image = [UIImage imageNamed:@"index_off"];
    NVCHome.tabBarItem.selectedImage = [UIImage imageNamed:@"index_on"];
    NVCHome.tabBarItem.title = @"首页";
    // 自动
    UINavigationController *NVCAuto = [[UINavigationController alloc] initWithRootViewController:[[AutoChangerController alloc] init]];
    NVCAuto.navigationBar.translucent = NO;
    
    NVCAuto.tabBarItem.image = [UIImage imageNamed:@"self_off"];
    NVCAuto.tabBarItem.selectedImage = [UIImage imageNamed:@"self_on"];
    NVCAuto.tabBarItem.title = @"自动";
    
    // 消息
    UINavigationController *NVCMessage = [[UINavigationController alloc] initWithRootViewController:[[AutoChangerController alloc] init]];
    NVCMessage.navigationBar.translucent = NO;
    
    NVCMessage.tabBarItem.image = [UIImage imageNamed:@"message_off"];
    NVCMessage.tabBarItem.selectedImage = [UIImage imageNamed:@"message_on"];
    NVCMessage.tabBarItem.title = @"消息";
    UITabBarController *tabbar = [[UITabBarController alloc] init];
    tabbar.viewControllers = @[NVCHome,NVCAuto,NVCMessage];
    //navigationbar背景颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
    // 普通状态
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       [UIColor grayColor], NSForegroundColorAttributeName,[UIFont systemFontOfSize:15],NSFontAttributeName,
                                                       nil] forState:UIControlStateNormal];
    UIColor *titleHighlightedColor = [UIColor redColor];
    
    //高亮状态
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       titleHighlightedColor, NSForegroundColorAttributeName,[UIFont systemFontOfSize:15],NSFontAttributeName,
                                                       nil] forState:UIControlStateSelected];
    
    self.window.rootViewController = tabbar;
    
    
    // @"everLaunched" 用来判断用户以前是否登录过
    // @"firstLaunch" 用来判断 在程序的其他部分的判断
    // 第一次程序启动的时候，key @"everLaunched" 不会被赋值的，设置为YES
    //                                          @"firstLaunch" 设置为YES。
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"everLaunched"]) {
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"everLaunched"];
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
        ViewController *firstView = [[ViewController alloc]init];
        self.window.rootViewController = firstView;
    }else{
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
    }
    

    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
